<template>
    <el-dialog
  :title="dialogType==0 ? '添加':'修改'"
  :visible.sync="dialogVisible"
  width="40%"
  :before-close="handleClose">
  <!-- 内容部分 -->
  <el-form 
  :model="ruleForm" 
  :rules="rules" 
  ref="ruleForm" 
  label-width="100px">
    <el-form-item label="姓名" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
    </el-form-item>
     <el-form-item label="人员编号" prop="humnum">
        <el-input v-model="ruleForm.humnum"></el-input>
    </el-form-item>

    <el-form-item label="所属角色" prop="typehum">
    <el-select v-model="ruleForm.typehum" placeholder="请选择角色">
      <el-option label="管理员" :value="1"></el-option>
      <el-option label="街道负责人" :value="2"></el-option>
    </el-select>
    </el-form-item>

    <el-form-item label="说明" prop="explain">
    <el-select v-model="ruleForm.explain" placeholder="请选择权限">
      <el-option label="该账号拥有所有权限" :value="1"></el-option>
      <el-option label="上传车位信息" :value="2"></el-option>
    </el-select>
    </el-form-item>
    <el-form-item label="活动时间" required>
    <el-col :span="11">
      <el-form-item prop="time">
        <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.time" style="width: 100%;"></el-date-picker>
      </el-form-item>
    </el-col>
    </el-form-item>
     <el-form-item label="是否有效" prop="boor">
    <el-select v-model="ruleForm.boor" placeholder="请选择权限">
      <el-option label="是" value="是"></el-option>
      <el-option label="否" value="否"></el-option>
    </el-select>
    </el-form-item>
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="closeDialog">取 消</el-button>
    <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
  </span>
</el-dialog>
</template>

<script>

import { addFunApi,updateFunApi } from '../../../api/PoliceofficerApi'
export default {
    props:['row','dialogType'],
 data() {
      return {
        dialogVisible: true, //控制显示隐藏
        ruleForm:{
            id:'',
            name:'',
            humnum:'',
            typehum:'',
            explain:'',
            time:'',
            boor:''
        },
        rules: {
          name: [
            { required: true, message: '请输入活动名称', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          humnum: [
            { required: true, message: '请输入警员编号', trigger: 'blur' },
            { min: 8, max: 8, message: '长度为8位数字', trigger: 'blur' }
          ],
          explain: [
            { required: true, message: '请选择说明信息', trigger: 'blur' },
            
          ],
          typehum: [
            { required: true, message: '请选择角色', trigger: 'change' }
          ],
          time: [
            { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
          ],
          boor: [
            { required: true, message: '请选择是否有效', trigger: 'change' }
          ],
         
        }

      }
    },
    mounted(){
        this.ruleForm = {...this.row}
    },
    methods: {
        
        submitForm(formName) {//提交按钮
        this.$refs[formName].validate((valid) => {
          if (valid) {//验证通过
            if(this.dialogType == 0){
            addFunApi(this.ruleForm).then(res=>{
                          console.log(res);
                            if(res.code == 200){
                                this.$emit('resettable')
                            }
                        })
            }else{
              updateFunApi(this.ruleForm).then(res=>{
                if(res.code == 200){
                                this.$emit('resettable')
                            }
              })
            }
             
          } else {
            
            return false;
          }
        });
      },
        closeDialog(){
            //关闭弹框
            this.$emit('closeDialog')
        },
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
            this.$emit('closeDialog')
          })
          .catch(_ => {});
      }
    }
}
</script>

<style>

</style>